package com.lighthouse.issue.base.service.impl;

import com.lighthouse.issue.base.dao.KnowledgeIssueRepository;
import com.lighthouse.issue.base.domain.KnowledgeIssue;
import com.lighthouse.issue.base.mapper.KnowledgeIssueMapper;
import com.lighthouse.issue.base.service.IKnowledgeIssueService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 问题Service业务层处理
 * 
 * @author ysz
 * @date 2024-02-03
 */
@Service
public class KnowledgeIssueServiceImpl implements IKnowledgeIssueService 
{
    @Autowired
    private KnowledgeIssueMapper knowledgeIssueMapper;

    @Autowired
    private KnowledgeIssueRepository knowledgeIssueRepository;

    /**
     * 查询问题
     * 
     * @param issueId 问题主键
     * @return 问题
     */
    @Override
    public KnowledgeIssue selectKnowledgeIssueByIssueId(Long issueId)
    {
        return knowledgeIssueMapper.selectKnowledgeIssueByIssueId(issueId);
    }

    /**
     * 查询问题列表
     * 
     * @param knowledgeIssue 问题
     * @return 问题
     */
    @Override
    public List<KnowledgeIssue> selectKnowledgeIssueList(KnowledgeIssue knowledgeIssue)
    {
        return knowledgeIssueRepository.findAll();
    }

    /**
     * 新增问题
     * 
     * @param knowledgeIssue 问题
     * @return 结果
     */
    @Override
    public KnowledgeIssue insertKnowledgeIssue(KnowledgeIssue knowledgeIssue)
    {
        if (StringUtils.isEmpty(knowledgeIssue.getIssueId())) {
            knowledgeIssue.setCreateInfo();
        } else {
            knowledgeIssue.setUpdateInfo();
        }
        return knowledgeIssueRepository.save(knowledgeIssue) == null ? null : knowledgeIssue;
    }

    /**
     * 修改问题
     * 
     * @param knowledgeIssue 问题
     * @return 结果
     */
    @Override
    public int updateKnowledgeIssue(KnowledgeIssue knowledgeIssue)
    {
        return knowledgeIssueMapper.updateKnowledgeIssue(knowledgeIssue);
    }

    /**
     * 批量删除问题
     * 
     * @param issueIds 需要删除的问题主键
     * @return 结果
     */
    @Override
    public int deleteKnowledgeIssueByIssueIds(Long[] issueIds)
    {
        return knowledgeIssueMapper.deleteKnowledgeIssueByIssueIds(issueIds);
    }

    /**
     * 删除问题信息
     * 
     * @param issueId 问题主键
     * @return 结果
     */
    @Override
    public int deleteKnowledgeIssueByIssueId(Long issueId)
    {
        return knowledgeIssueMapper.deleteKnowledgeIssueByIssueId(issueId);
    }
}
